const sms = require('leancloud-storage')

sms.init({
    appId:'vDn0g43nD7rQy50Lc0EDSM8e-gzGzoHsz',
    appKey:'ykBRoGpvS8554LkjXN5PxSId',
    serverURLs:'https://vdn0g43n.lc-cn-n1-shared.com',
})

module.exports = {
    SendCode(req,resp){
        let {phone} = req.body
        sms.Cloud.requestSmsCode({
            mobilePhoneNumber: phone,
            name: '万卷书城',
            op: '万卷书城注册验证码',
            ttl: 10, // 验证码有效时间为 10 分钟
            sing: 'web',
        }).then(res => {
            resp.send({code:200,msg:'短信发送成功'})
        }).catch(err => {
            resp.send({code:400,msg:'短信发送失败，请输入正确的手机号'})
        })
        console.log(phone)
    },
    Login(req,resp){
        let {phone,Code} = req.body
        sms.Cloud.verifySmsCode(Code, phone).then(function(data){
            // 验证成功
            resp.send({code:200,msg:'验证成功'})
        }, function(err){
            // 验证失败
            resp.send({code:200,msg:'验证失败'})
        });
    },
}